
package com.beiru.photoBrowser;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReadableArray;
import com.kevin.photo_browse.ImageBrowseIntent;

import java.util.ArrayList;
import java.util.List;

public class RNPhotobrowserModule extends ReactContextBaseJavaModule {

    private final ReactApplicationContext reactContext;

    public RNPhotobrowserModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.reactContext = reactContext;
    }

    @Override
    public String getName() {
        return "RNPhotobrowser";
    }

    @ReactMethod
    public void browserPhotos(ReadableArray urls, int index) {
        List<String> imageList = new ArrayList<>();
        int size = urls.size();
        if (size == 0) {
            return;
        }
        for (int i = 0; i < size; i++) {
            imageList.add(urls.getString(i));
        }
        ImageBrowseIntent.showUrlImageBrowse(reactContext.getCurrentActivity(), imageList, index);

    }
}
